package org.yaac.client.conf;

import javax.inject.Inject;
import javax.inject.Provider;

import org.yaac.client.place.OverviewPlace;

import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.web.bindery.event.shared.EventBus;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class YaacPlaceHistoryHandlerProvider implements Provider<PlaceHistoryHandler> {

	private final PlaceController placeController;
	
	private final EventBus eventBus;
	
	private final PlaceHistoryMapper placeHistoryMapper;
	
	/**
	 * @param placeController
	 * @param eventBus
	 * @param placeHistoryMapper
	 */
	@Inject
	YaacPlaceHistoryHandlerProvider(PlaceController placeController,
			EventBus eventBus, PlaceHistoryMapper placeHistoryMapper) {
		super();
		this.placeController = placeController;
		this.eventBus = eventBus;
		this.placeHistoryMapper = placeHistoryMapper;
	}

	@Override
	public PlaceHistoryHandler get() {
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(placeHistoryMapper);
		// default place
		historyHandler.register(placeController, eventBus, new OverviewPlace());
		return historyHandler;
	}
}
